/**
 * 
 */
package com.lijin.workshop.web.action;

import java.util.Map;

import org.apache.log4j.Logger;

import com.lijin.workshop.cache.CacheManager;
import com.lijin.workshop.cache.CacheType;

/**
 * 缓存刷新Action
 * 
 * @author jin
 *
 */
public class CacheAction extends BaseAction {
	private static final long serialVersionUID = -7333801710713785897L;
	
	private static final Logger logger = Logger.getLogger(CacheAction.class);
	
	private String cacheTp;
	
	public String execute() {
		return "refreshPage";
	}
	
	public String refresh() {
		logger.info("缓存刷新开始，缓存类型为:" + cacheTp);
		try {
			if (cacheTp.equals("ALL")) {
				CacheManager.refreshAllCaches();
			} else {
				CacheManager.refreshCache(cacheTp);
			}
			ajaxResult = AJAX_RESULT_SUCC;
		} catch (Exception e) {
			logger.error("刷新缓存失败", e);
			ajaxResult = AJAX_RESULT_FAIL;
		}
		return AJAX_RESULT_TYPE;
	}
	
	public Map<String, String> getCacheTypes() {
		return CacheType.getMap();
	}

	public String getCacheTp() {
		return cacheTp;
	}

	public void setCacheTp(String cacheTp) {
		this.cacheTp = cacheTp;
	}
	
}
